#CalThreeKingdomsV1.py
import jieba
txt = open("threekingdoms.txt", "r", encoding='utf-8').read()
words  = jieba.lcut(txt)#产生一个所有切词的列表
counts = {}#核心代码，构造一个字典
for word in words:
    if len(word) == 1:
        continue
    else:#对列表出现不止一次的词语，进行计数统计
        counts[word] = counts.get(word,0) + 1
items = list(counts.items())#在对字典转换为列表，才可以用排序sort
items.sort(key=lambda x:x[1], reverse=True) 
for i in range(15):
    word, count = items[i]#对前15位进行输出
    print ("{0:<10}{1:>5}".format(word, count))
